package goleetcode

func rob(root *TreeNode) int {
	res := robTree(root)
	return max(res[0], res[1])
}

func robTree(root *TreeNode) []int {
	if root == nil {
		return []int{0,0}
	}

	res := [2]int{}
	left := robTree(root.Left)
	right := robTree(root.Right)

	res[0] = max(left[0], left[1]) + max(right[0], right[1])
	res[1] = left[0] + right[0] + root.Val

	return res[:]
}